import { IsString, IsNotEmpty, IsBoolean, IsEnum } from 'class-validator';
import { DeviceType, User } from '../entities/user.entity';
import { PickType, PartialType } from '@nestjs/mapped-types';

export class CreateWeChatDto {
  @IsString()
  @IsNotEmpty()
  code: string;
}

// 基础DTO包含所有必填字段
export class UserInfoDto
  implements
    Pick<
      User,
      | 'openId'
      | 'unionid'
      | 'nickName'
      | 'avatar'
      | 'mobile'
      | 'is_admin'
      | 'device_info'
      | 'sessionKey'
      | 'loginType'
    >
{
  @IsString()
  @IsNotEmpty()
  openId: string;

  @IsString()
  unionid: string;

  @IsString()
  nickName: string;

  @IsString()
  avatar: string;

  @IsString()
  mobile: string;

  @IsBoolean()
  is_admin: boolean;

  @IsEnum(DeviceType)
  device_info: DeviceType;

  @IsString()
  sessionKey: string;

  @IsString()
  loginType: string;
}

// 创建用户DTO
export class CreateUserDto extends PickType(UserInfoDto, [
  'openId',
  'nickName',
]) {}

// 更新用户DTO
export class UpdateUserDto extends PartialType(UserInfoDto) {}
